package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BieVillage;
import com.ruoyi.system.service.IBieVillageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 住宅小区Controller
 * 
 * @author zxl
 * @date 2021-05-03
 */
@RestController
@RequestMapping("/system/village")
public class BieVillageController extends BaseController
{
    @Autowired
    private IBieVillageService bieVillageService;

    /**
     * 查询住宅小区列表
     */
    @PreAuthorize("@ss.hasPermi('system:village:list')")
    @GetMapping("/list")
    public TableDataInfo list(BieVillage bieVillage)
    {
        startPage();
        List<BieVillage> list = bieVillageService.selectBieVillageList(bieVillage);
        return getDataTable(list);
    }

    /**
     * 导出住宅小区列表
     */
    @PreAuthorize("@ss.hasPermi('system:village:export')")
    @Log(title = "住宅小区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BieVillage bieVillage)
    {
        List<BieVillage> list = bieVillageService.selectBieVillageList(bieVillage);
        ExcelUtil<BieVillage> util = new ExcelUtil<BieVillage>(BieVillage.class);
        return util.exportExcel(list, "住宅小区数据");
    }

    /**
     * 获取住宅小区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:village:query')")
    @GetMapping(value = "/{villageId}")
    public AjaxResult getInfo(@PathVariable("villageId") String villageId)
    {
        return AjaxResult.success(bieVillageService.selectBieVillageById(villageId));
    }

    /**
     * 新增住宅小区
     */
    @PreAuthorize("@ss.hasPermi('system:village:add')")
    @Log(title = "住宅小区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BieVillage bieVillage)
    {
        return toAjax(bieVillageService.insertBieVillage(bieVillage));
    }

    /**
     * 修改住宅小区
     */
    @PreAuthorize("@ss.hasPermi('system:village:edit')")
    @Log(title = "住宅小区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BieVillage bieVillage)
    {
        return toAjax(bieVillageService.updateBieVillage(bieVillage));
    }

    /**
     * 删除住宅小区
     */
    @PreAuthorize("@ss.hasPermi('system:village:remove')")
    @Log(title = "住宅小区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{villageIds}")
    public AjaxResult remove(@PathVariable String[] villageIds)
    {
        return toAjax(bieVillageService.deleteBieVillageByIds(villageIds));
    }
}
